package graphs;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * displays a scatter plot for the given data
 * 
 * @author lindsaykubasik
 * 
 */
@SuppressWarnings("serial")
public class Scatterplot extends AbstractNumericalPlot
{
    /**
     * Construct panel so that it knows its size
     */
    public Scatterplot()
    {
        myData = null;
        myLabels = null;
        myXvals = null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
     */
    public void paintComponent(Graphics pen)
    {
        Dimension bounds = getSize();
        if (myLabels.size() > 1)
            pen.drawString(myLabels.get(1), bounds.width - 8
                    * myLabels.get(1).length(), bounds.height);
        if (myLabels.size() > 0)
            pen.drawString(myLabels.get(0), (bounds.width / 2), 20);
        if (myLabels.get(0) != null)
            pen.drawString(myLabels.get(0), (bounds.width / 2), 20);

        List<Color> colors = new ArrayList<Color>();
        double[] yMinMax = findYMinMax(myData, myXvals, colors);
        double yMax = yMinMax[0];
        double yMin = yMinMax[1];
        double[] xMinMax = findXMinMax(myData, myXvals);
        double xMax = xMinMax[0];
        double xMin = xMinMax[1];
        drawGraph(pen, bounds, colors, null, yMax, xMax, yMin, xMin, myXvals,
                myData, myLabels);
    }

    /*
     * (non-Javadoc)
     * 
     * @see graphs.AbstractGraph#toString()
     */
    public String toString()
    {
        return "Scatterplot";
    }

    /*
     * (non-Javadoc)
     * 
     * @see graphs.AbstractNumericalPlot#plotPoints(java.awt.Graphics,
     * java.util.Map, int, int, java.awt.Point, java.awt.Dimension)
     */
    protected void plotPoints(Graphics pen, Map<Integer, List<Point>> points,
            int count, int i, Point dot1, Dimension size)
    {
        pen.fillOval(size.width - 3, size.height - 3, 7, 7);

    }

}